home *** CD-ROM | disk | FTP | other *** search
- /*
- File: GXEditDoc.c
-
- Contains:
-
- Written by: Barton R. House
-
- Copyright: © 1993 by Apple Computer, Inc., All rights reserved.
-
- */
-
- /* GX includes */
-
- #include "PrintingManager.h"
- #include "graphics routines.h"
- #include "graphics libraries.h"
- #include "font routines.h"
- #include "math routines.h"
- #include "layout routines.h"
- #include "layout types.h"
-
- #include "GXEdit.h"
- #include "GXEditDebug.h"
- #include "GXEditDoc.h"
- #include "GXEditParagraph.h"
- #include "GXEditStyle.h"
- #include "GXEditSelection.h"
- #include "GXEditError.h"
- #include "GXEditUtils.h"
- #include "GXEditScrap.h"
- #include "GXEditReplace.h"
- #include "GXEditValidation.h"
- #include "GXEditLine.h"
-
- #define kScrollRate 45
-
- unsigned char * gDefaultFonts[] = {
- "\pGeneva",
- "\pTimes",
- "\pMonaco"
- };
-
- static void CalcOffsets(DocPtr dp, short paragraphIndex);
- static void CalcStarts(DocPtr dp, short paragraphIndex);
-
- static void InsertNewParagraph(DocPtr dp, short paragraphIndex, short paragraphOffset);
-
- static void CalcPrintPages(DocPtr dp, gxJob printJob, short * numPages, long *** pageStartsPtr);
- static gxShape GetAPage(DocPtr dp, long docOffset);
-
- static void InitRunControl(gxRunControls * runControl);
-
- static void BlinkCursor(DocPtr dp);
-
- static void Insert(DocPtr dp, void * text, short startNumText, short styleIndex);
- static void Clear(DocPtr dp);
- static void Paste(DocPtr dp);
- static void Copy(DocPtr dp);
-
- static void CalcPositionAndDraw(DocPtr dp, short startIndex);
- static void Draw(DocPtr dp, long start, long end);
- static void Position(DocPtr dp, long docOffset, long * start, long * end);
-
- static void HitTest(DocPtr dp, Point where, long * docOffset, Boolean * endOfLine, Boolean extend);
-
- static void CheckCaretVisibility(DocPtr dp);
-
- static void DoEraseToEndOfView(DocPtr dp);
-
- static void GetOffset(DocPtr dp, short offsetType, long * newOffset, Boolean * endOfLine);
-
-
- void NewDoc(DocHan * docHanPtr, Rect * viewRect, gxViewPort docViewPort, short leftMargin, short rightMargin)
- {
- DocPtr dp, * doc;
- gxFont defaultFont;
- short index;
- short numDefaultFonts;
- gxViewPort newViewPort;
- gxShape clip;
- gxRectangle rect;
- StyleRec defaultStyle;
-
- doc = (DocHan) NewHandle(sizeof(DocRec));
-
- *docHanPtr = doc;
-
- HLock((Handle) doc);
-
- dp = *doc;
-
- dp->magic = kGXEditMagic;
-
- /* initialize error reporting */
-
- dp->error = gx_edit_no_error;
- dp->stickyError = gx_edit_no_error;
- dp->errorProc = nil;
-
- dp->length = 0;
- dp->lineWidth = viewRect->right - viewRect->left - leftMargin - rightMargin;
- dp->leftMargin = leftMargin;
- dp->rightMargin = rightMargin;
- dp->viewHeight = viewRect->bottom - viewRect->top;
-
- dp->numText = 0;
-
- /* initialize the default gxStyle */
-
- dp->numStyles = 0;
- dp->styles = (StyleHan) NewHandle(0);
-
- defaultStyle.textStyle = GXNewStyle();
-
- GXSetStyleTextSize(defaultStyle.textStyle, ff(24));
-
- /* initialize the default layout options */
-
- dp->currentLayoutOptions.width = ff(dp->lineWidth);
- dp->currentLayoutOptions.flush = gxFlushLeft;
- dp->currentLayoutOptions.just = gxNoJustification;
- dp->currentLayoutOptions.flags = 0; /* no flags set */
- dp->currentLayoutOptions.baselineRec = nil;
-
- /* initialize the default script and language */
-
- dp->currentPlatform = GXGetStyleEncoding(defaultStyle.textStyle, &dp->currentScript, &dp->currentLanguage);
-
- /* find a good default gxFont */
-
- defaultFont = (gxFont) -1;
-
- numDefaultFonts = sizeof(gDefaultFonts) / sizeof(char *);
-
- for(index = 0; index < numDefaultFonts, defaultFont == (gxFont) -1; index++)
- GXFindFonts(nil, gxFamilyFontName,
- gxMacintoshPlatform, gxRomanScript, gxNoLanguage,
- gDefaultFonts[index][0], &gDefaultFonts[index][1],
- 1, 1, &defaultFont);
-
- if(defaultFont == (gxFont) -1)
- GXFindFonts(nil, gxFamilyFontName,
- gxMacintoshPlatform, gxRomanScript, gxNoLanguage,
- 0, nil, 1, 1, &defaultFont);
-
- if(defaultFont != (gxFont) -1)
- GXSetStyleFont(defaultStyle.textStyle, defaultFont);
-
- dp->numCurrentFonts = 1;
- dp->currentFonts = (gxFont **) NewHandle(sizeof(gxFont));
- (*dp->currentFonts)[0] = GXGetStyleFont(defaultStyle.textStyle);
-
- dp->numCurrentStyles = 1;
- dp->currentStyles = (short **) NewHandle(sizeof(short));
- (*dp->currentStyles)[0] = AddDocTextStyle(dp, defaultStyle.textStyle);
-
- GXDisposeStyle(defaultStyle.textStyle);
-
- /* set the view rect and gxViewPort */
-
- dp->viewRect = *viewRect;
- dp->top = 0;
- dp->maxTop = 0;
-
- newViewPort = GXCopyToViewPort(nil, docViewPort);
- GXSetViewPortParent(newViewPort, docViewPort);
-
- rect.top = ff(viewRect->top);
- rect.left = ff(viewRect->left);
- rect.right = ff(viewRect->right);
- rect.bottom = ff(viewRect->bottom);
- clip = GXNewRectangle(&rect);
-
- /* This ignores is needed because we do not keep track of the current
- clip of the view port. Thus, we will often set the clip to the same rect
- which generates a notice*/
-
- #ifdef debugging
- GXIgnoreGraphicsNotice(clip_already_set);
- #endif
-
- GXSetViewPortClip(newViewPort, clip);
-
- #ifdef debugging
- GXPopGraphicsNotice();
- #endif
-
- GXDisposeShape(clip);
-
- dp->docViewPort = newViewPort;
-
- /* setup layout orientation */
-
- dp->verticalText = false; /* initial value is non-vertical */
-
- /* the document has not been drawn */
-
- dp->drawn = false;
-
- if(dp->verticalText)
- dp->bottomClear = dp->viewRect.left;
- else
- dp->bottomClear = dp->viewRect.bottom;
-
- /* allocate offscreen gxBitmap and viewport */
-
- dp->offscreenBytes = nil;
- dp->offscreenPort = nil;
- dp->offscreenDevice = nil;
- dp->offscreenGroup = nil;
- dp->offscreenBitmap = nil;
-
- gxEditBuildOffscreen(dp);
-
- /* now initialize an empty paragraph */
-
- dp->numParagraphs = 1;
- dp->paragraphs = (ParaHan) NewHandle(sizeof(ParaRec));
-
- HLock((Handle) dp->paragraphs);
-
- gxEditNewParagraph(dp, *dp->paragraphs, (*dp->currentStyles)[0]);
-
- HUnlock((Handle) dp->paragraphs);
-
- CalcOffsets(dp, 0);
- CalcStarts(dp, 0);
-
- /* selection at the start of the document */
-
- dp->emptyStyle = (*dp->currentStyles)[0];
- SetSelection(dp, 0, 0, false, false, true);
-
- /* mark the document as unactive */
-
- dp->active = false;
-
- /* setup the scrap to be empty */
-
- dp->scrap.numRuns = 0;
- dp->scrap.runs = (NewRunHan) NewHandle(0);
-
-
- HUnlock((Handle) doc);
-
- }
-
- void DisposeDoc(DocHan doc)
- {
- DocPtr dp;
- ParaPtr pp;
- short paragraphIndex;
- StylePtr sp;
- short styleIndex;
-
- HLock((Handle) doc);
-
- dp = *doc;
-
- gxEditDisposeScrap(dp);
-
- HLock((Handle) dp->paragraphs);
-
- pp = *dp->paragraphs;
-
- for(paragraphIndex=0; paragraphIndex < dp->numParagraphs; paragraphIndex++, pp++)
- gxEditDisposeParagraph(dp, pp);
-
- HUnlock((Handle) dp->paragraphs);
-
- DisposeHandle((Handle) dp->paragraphs);
-
- HLock((Handle) dp->styles);
-
- sp = *dp->styles;
-
- for(styleIndex=0; styleIndex < dp->numStyles; styleIndex++, sp++)
- GXDisposeStyle(sp->textStyle);
-
- HUnlock((Handle) dp->styles);
-
- DisposeHandle((Handle) dp->styles);
-
- DisposeHandle((Handle) dp->currentStyles);
-
- GXDisposeViewPort(dp->docViewPort);
-
- gxEditDisposeOffscreen(dp);
-
- HUnlock((Handle) doc);
-
- DisposeHandle((Handle) doc);
- }
-
- void DocSetSelection(DocPtr dp, long selStart, long selEnd)
- {
- SetSelection(dp, selStart, selEnd, true, false, true);
-
- Draw(dp, 0, dp->viewHeight);
- }
-
- void DocInsert(DocPtr dp, void *text, short startNumText)
- {
- short styleIndex;
-
- /* make sure we are adding using the current script and lanuaguge */
-
- styleIndex = SetDocStyleEncoding(dp, (*dp->currentStyles)[0], dp->currentPlatform, dp->currentScript, dp->currentLanguage);
-
- Insert(dp, text, startNumText, styleIndex);
- CheckCaretVisibility(dp);
- Draw(dp, 0, dp->viewHeight);
- }
-
- void DocClear(DocPtr dp)
- {
- if(dp->selection.startDocOffset == dp->selection.endDocOffset)
- return; /* nothing to clear */
-
- Clear(dp);
-
- /* reflow the document */
-
- while(DocReflow(dp)) ;
-
- CheckCaretVisibility(dp);
-
- Draw(dp, 0, dp->viewHeight);
-
-
- }
-
- long DocHitTest(DocPtr dp, Point where)
- {
- long docOffset;
- Boolean endOfLine;
-
- HitTest(dp, where, &docOffset, &endOfLine, false);
-
- return(docOffset);
-
- }
-
- void DocUpdate(DocPtr dp, gxRectangle * updateRect)
- {
- ParaPtr pp;
- short paragraphIndex;
- long start, end;
-
- if(dp->verticalText) {
-
- start = FixedToInt(updateRect->right);
- end = FixedToInt(updateRect->left);
-
- if(start < end)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- if(start > dp->viewRect.right)
- start = dp->viewRect.right;
-
- if(end < dp->viewRect.left)
- end = dp->viewRect.left;
-
- if(start < end)
- return;
-
- } else {
-
- start = FixedToInt(updateRect->top);
- end = FixedToInt(updateRect->bottom);
-
- if(start > end)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- if(start < dp->viewRect.top)
- start = dp->viewRect.top;
-
- if(end > dp->viewRect.bottom)
- end = dp->viewRect.bottom;
-
- if(start > end)
- return;
- }
-
- if(dp->dirty)
- CalcStarts(dp, 0);
-
- HLock((Handle) dp->paragraphs);
-
- /* map the view area coords to doc coords */
-
- if(dp->verticalText) {
- start = dp->viewRect.right - start + dp->top;
- end = dp->viewRect.right - end + dp->top;
- } else {
- start = start - dp->viewRect.top + dp->top;
- end = end - dp->viewRect.top + dp->top;
- }
-
- /* loop through all of the paragraphs, draw paragraphs that fall in the range */
-
- /* this loop should be optimized in the future */
-
- pp = *dp->paragraphs;
-
- for(paragraphIndex=0; paragraphIndex < dp->numParagraphs; pp++, paragraphIndex++)
- if((pp->start + GetParagraphHeight(dp, pp)) >= start && (pp->start < end)) {
-
- pp->drawn = false;
- DrawParagraph(dp, pp, start, end);
-
- }
-
- /* erase from the last paragraph to end of view if necessary */
-
- if(paragraphIndex == dp->numParagraphs)
- DoEraseToEndOfView(dp);
-
- dp->drawn = true;
-
- HUnlock((Handle) dp->paragraphs);
-
- }
-
- void DocClick(DocPtr dp, Point where, Boolean extend)
- {
- long docOffset;
- long startDocOffset;
- long endDocOffset;
- Boolean endOfLine;
- Boolean done;
- long oldDocOffset;
- Boolean firstTime;
-
- HitTest(dp, where, &docOffset, &endOfLine, extend);
-
- if(extend) {
-
- startDocOffset = dp->selection.startDocOffset;
- endDocOffset = dp->selection.endDocOffset;
-
- } else
- startDocOffset = docOffset;
-
- done = false;
- firstTime = true;
-
- while(!done) {
-
- if(extend) {
-
- if(docOffset > startDocOffset)
- SetSelection(dp, startDocOffset, docOffset, true, endOfLine, true);
- else
- SetSelection(dp, docOffset, endDocOffset, true, endOfLine, true);
-
- } else {
-
- if(docOffset > startDocOffset)
- SetSelection(dp, startDocOffset, docOffset, true, endOfLine, true);
- else if(!firstTime || docOffset != dp->selection.startDocOffset || docOffset != dp->selection.endDocOffset)
- SetSelection(dp, docOffset, startDocOffset, true, endOfLine, true);
-
- }
-
- Draw(dp, 0, dp->viewHeight);
-
- oldDocOffset = docOffset;
-
- do {
-
- if((done = !StillDown()))
- break;
-
- GetMouse(&where);
-
- HitTest(dp, where, &docOffset, &endOfLine, (firstTime ? extend : true));
-
- if(dp->verticalText) {
- if(where.h > dp->viewRect.right)
- DocScroll(dp, kScrollRate);
- else if(where.h < dp->viewRect.left)
- DocScroll(dp, -kScrollRate);
- } else {
- if(where.v < dp->viewRect.top)
- DocScroll(dp, kScrollRate);
- else if(where.v > dp->viewRect.bottom)
- DocScroll(dp, -kScrollRate);
- }
-
- } while(docOffset == oldDocOffset);
-
- firstTime = false;
-
- }
-
- }
-
- void DocScroll(DocPtr dp, short dv)
- {
- RgnHandle updateRgn;
- long top;
- long bottom;
- ParaPtr pp;
- LinePtr lp;
- short paraIndex;
- short lineIndex;
-
- if(dv < 0)
- dv = (dv < (dp->top - dp->maxTop) ? (dp->top - dp->maxTop) : dv);
- else
- dv = (dv > dp->top ? dp->top : dv);
-
- if(dv == 0)
- return;
-
- updateRgn = NewRgn();
-
- if(dp->verticalText)
- ScrollRect(&dp->viewRect, -dv, 0, updateRgn);
- else
- ScrollRect(&dp->viewRect, 0, dv, updateRgn);
-
- DisposeRgn(updateRgn);
-
- if(dv < 0) {
- top = dp->viewHeight + dv;
- bottom = dp->viewHeight;
- } else {
- top = 0;
- bottom = dv;
- }
- dp->top -= dv;
-
- /* mark any gxLine that falls in this range not drawn */
-
- top += dp->top;
- bottom += dp->top;
-
- if(dp->dirty) /* this shouldn't happen -- we need to test because we use paragraph starts */
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- HLock((Handle) dp->paragraphs);
-
- pp = *dp->paragraphs;
- for(paraIndex=0; paraIndex < dp->numParagraphs; paraIndex++, pp++)
- if(pp->start < bottom && (pp->start + GetParagraphHeight(dp, pp)) > top)
- for(lp = *pp->lines, lineIndex=0; lineIndex < pp->numLines; lineIndex++, lp++)
- if((pp->start + lp->start) < bottom && (pp->start + lp->start + lp->height) > top)
- lp->drawn = false;
-
- HUnlock((Handle) dp->paragraphs);
-
- Draw(dp, 0, dp->viewHeight);
-
- }
-
- long DocHeight(DocPtr dp)
- {
- if(dp->dirty)
- CalcStarts(dp, 0);
-
- return(dp->length);
- }
-
- void DocSize(DocPtr dp, Rect * viewRect)
- {
- gxShape clip;
- gxRectangle rect;
- short paraIndex;
- ParaPtr pp;
- LinePtr lp;
- short lineIndex;
-
- dp->viewRect = *viewRect;
-
- rect.top = ff(viewRect->top);
- rect.left = ff(viewRect->left);
- rect.right = ff(viewRect->right);
- rect.bottom = ff(viewRect->bottom);
-
- clip = GXNewRectangle(&rect);
-
- /* This ignores is needed because we do not keep track of the current
- clip of the view port. Thus, we will often set the clip to the same rect
- which generates a notice*/
-
- #ifdef debugging
- GXIgnoreGraphicsNotice(clip_already_set);
- #endif
-
- GXSetViewPortClip(dp->docViewPort, clip);
-
- #ifdef debugging
- GXPopGraphicsNotice();
- #endif
-
- GXDisposeShape(clip);
-
- DocSetMaxTop(dp);
-
- /* update the offscreen gxBitmap */
-
- gxEditBuildOffscreen(dp);
-
- /* change the line width and view height */
-
- if(dp->verticalText) {
- dp->lineWidth = dp->viewRect.bottom - dp->viewRect.top - dp->leftMargin - dp->rightMargin;
- dp->viewHeight = dp->viewRect.right - dp->viewRect.left;
- } else {
- dp->lineWidth = dp->viewRect.right - dp->viewRect.left - dp->leftMargin - dp->rightMargin;
- dp->viewHeight = dp->viewRect.bottom - dp->viewRect.top;
- }
-
- /* change the line width for all of the paragraphs */
-
- pp = *dp->paragraphs;
-
- for(paraIndex = 0; paraIndex < dp->numParagraphs; paraIndex++, pp++) {
-
- if(pp->width != dp->lineWidth) {
-
- pp->width = dp->lineWidth;
- pp->layoutOptions.width = ff(pp->width);
-
- if(pp->numLines) {
-
- pp->reflow = true;
- (*pp->lines)[0].reflow = true;
-
- /* make sure we mark all lines as dirty so that a new layout calculation is forced */
-
- lp = *pp->lines;
-
- for(lineIndex = 0; lineIndex < pp->numLines; lineIndex++, lp++)
- lp->dirty = true;
-
- }
-
- }
-
- }
-
- /* mark the entire document as not drawn */
-
- dp->drawn = false;
-
- }
-
- long DocSetTop(DocPtr dp, long top)
- {
- short dv;
-
- if(top > dp->maxTop)
- top = dp->maxTop;
-
- dv = dp->top - top;
-
- if(dv != 0)
- DocScroll(dp, dv);
-
- return(dp->top);
- }
-
- long DocGetTop(DocPtr dp)
- {
- return(dp->top);
- }
-
- long DocGetMaxTop(DocPtr dp)
- {
- return(dp->maxTop);
- }
-
- void DocKey(DocPtr dp, char key)
- {
- long startOffset;
- Boolean setAndDraw = false;
- Boolean setMaxLineOffset;
- Boolean endOfLine;
-
- endOfLine = dp->selection.endOfLine;
-
- switch(key) {
- case '\b':
-
- if(dp->selection.startDocOffset == dp->selection.endDocOffset && dp->selection.startDocOffset != 0) {
- startOffset = dp->selection.endDocOffset;
- GetOffset(dp, kPreviousOffset, &startOffset, &endOfLine);
- SetSelection(dp, startOffset, dp->selection.endDocOffset, false, endOfLine, true);
- }
-
- DocClear(dp);
-
- break;
-
- case 0x1c: /* left arrow */
-
-
- if(dp->verticalText) {
- startOffset = dp->selection.endDocOffset;
- GetOffset(dp, kDownOffset, &startOffset, &endOfLine);
- } else {
- startOffset = dp->selection.startDocOffset;
- GetOffset(dp, kVisualLeftOffset, &startOffset, &endOfLine);
- }
-
-
- setAndDraw = true;
- setMaxLineOffset = !dp->verticalText;
-
- break;
-
- case 0x1d: /* right arrow */
-
- if(dp->verticalText) {
- startOffset = dp->selection.startDocOffset;
- GetOffset(dp, kUpOffset, &startOffset, &endOfLine);
- } else {
- startOffset = dp->selection.endDocOffset;
- GetOffset(dp, kVisualRightOffset, &startOffset, &endOfLine);
- }
-
- setAndDraw = true;
- setMaxLineOffset = !dp->verticalText;
-
- break;
-
- case 0x1e: /* up arrow */
-
- startOffset = dp->selection.startDocOffset;
-
- if(dp->verticalText)
- GetOffset(dp, kVisualLeftOffset, &startOffset, &endOfLine);
- else
- GetOffset(dp, kUpOffset, &startOffset, &endOfLine);
-
- setAndDraw = true;
- setMaxLineOffset = dp->verticalText;
-
- break;
-
- case 0x1f: /* down arrow */
-
- startOffset = dp->selection.endDocOffset;
-
- if(dp->verticalText)
- GetOffset(dp, kVisualRightOffset, &startOffset, &endOfLine);
- else
- GetOffset(dp, kDownOffset, &startOffset, &endOfLine);
-
- setAndDraw = true;
- setMaxLineOffset = dp->verticalText;
-
- break;
-
- default:
- DocInsert(dp, (void *) &key, 1);
- break;
- }
-
- if(setAndDraw) {
-
- SetSelection(dp, startOffset, startOffset, false, endOfLine, setMaxLineOffset);
- Draw(dp, 0, dp->viewHeight);
- }
- }
-
- void DocSetTextFonts(DocPtr dp, short numFonts, gxFont * srcFonts, gxFont * dstFonts)
- {
- short * newStyles;
-
- if(dp->numCurrentStyles != 0) {
-
- newStyles = (short *) NewPtr(dp->numCurrentStyles * sizeof(short));
-
- HLock((Handle) dp->currentStyles);
-
- ModifyStyleTextFonts(dp, numFonts, srcFonts, dstFonts, dp->numCurrentStyles, *dp->currentStyles, newStyles);
-
- if(SetSelectionStyles(dp, dp->numCurrentStyles, *dp->currentStyles, newStyles))
- CalcPositionAndDraw(dp, dp->selection.startParaIndex);
-
- HUnlock((Handle) dp->currentStyles);
-
- DisposePtr((Ptr) newStyles);
-
- SetSelection(dp, dp->selection.startDocOffset, dp->selection.endDocOffset, false, dp->selection.endOfLine, false);
-
- } else
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- }
-
- void DocGetTextFonts(DocPtr dp, short * numFonts, gxFont * fonts)
- {
-
- if(numFonts != nil)
- *numFonts = dp->numCurrentFonts;
-
- if(fonts != nil)
- BlockMove((Ptr) *dp->currentFonts, (Ptr) fonts, sizeof(gxFont) * dp->numCurrentFonts);
- }
-
- void DocSetTextSize(DocPtr dp, short size)
- {
- short * newStyles;
-
- if(dp->numCurrentStyles != 0) {
-
- newStyles = (short *) NewPtr(dp->numCurrentStyles * sizeof(short));
-
- HLock((Handle) dp->currentStyles);
-
- ModifyStyleTextSize(dp, size, dp->numCurrentStyles, *dp->currentStyles, newStyles);
-
- if(SetSelectionStyles(dp, dp->numCurrentStyles, *dp->currentStyles, newStyles))
- CalcPositionAndDraw(dp, dp->selection.startParaIndex);
-
- HUnlock((Handle) dp->currentStyles);
-
- DisposePtr((Ptr) newStyles);
-
- SetSelection(dp, dp->selection.startDocOffset, dp->selection.endDocOffset, false, dp->selection.endOfLine, false);
-
- } else
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- }
-
- short DocGetTextSize(DocPtr dp)
- {
- return(dp->currentSize);
- }
-
- void DocSetFeatures(DocPtr dp, gxFont fontId, short numFeatureGroups,
- short * srcFeatureGroupSizes,
- gxRunFeature ** srcFeatureGroups,
- short * dstFeatureGroupSizes,
- gxRunFeature ** dstFeatureGroups)
- {
- short ** newStyles;
-
- if(dp->numCurrentStyles != 0) {
-
- newStyles = (short **) NewHandle(dp->numCurrentStyles * sizeof(short));
-
- HLock((Handle) dp->currentStyles);
- HLock((Handle) newStyles);
-
- ModifyStyleFeatures(dp, fontId, numFeatureGroups,
- srcFeatureGroupSizes, srcFeatureGroups,
- dstFeatureGroupSizes, dstFeatureGroups,
- dp->numCurrentStyles, *dp->currentStyles, *newStyles);
-
- if(SetSelectionStyles(dp, dp->numCurrentStyles, *dp->currentStyles, *newStyles))
- CalcPositionAndDraw(dp, dp->selection.startParaIndex);
-
- HUnlock((Handle) dp->currentStyles);
- HUnlock((Handle) newStyles);
-
- DisposeHandle((Handle) newStyles);
-
- SetSelection(dp, dp->selection.startDocOffset, dp->selection.endDocOffset, false, dp->selection.endOfLine, false);
-
- } else
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- }
-
- void DocGetFeatures(DocPtr dp, gxFont fontId, short * numFeatureGroupsPtr,
- short *** featureGroupSizesPtr,
- gxRunFeature **** featureGroupsPtr)
- {
-
- if(dp->numCurrentStyles != 0) {
-
- HLock((Handle) dp->currentStyles);
-
- UnionStyleFeatures(dp, dp->numCurrentStyles, *dp->currentStyles,
- fontId, numFeatureGroupsPtr, featureGroupSizesPtr, featureGroupsPtr);
-
- HUnlock((Handle) dp->currentStyles);
-
-
- } else {
-
- *numFeatureGroupsPtr = 0;
- *featureGroupSizesPtr = nil;
- *featureGroupsPtr = nil;
- }
-
- }
-
- void DocGetSelectionStyles(DocPtr dp, short * numStyles, gxStyle * styles)
- {
- short i;
-
- if(numStyles != nil)
- *numStyles = dp->numCurrentStyles;
-
- if(styles != nil)
- for(i=0; i<dp->numCurrentStyles;i++)
- styles[i] = GetDocStyle(dp, (*dp->currentStyles)[i])->textStyle;
-
- }
-
- void DocSetSelectionStyles(DocPtr dp, gxStyle * newTextStyles)
- {
- short * newStyles;
- short i;
- StyleRec newStyle;
-
- if(dp->numCurrentStyles != 0) {
-
- newStyles = (short *) NewPtr(dp->numCurrentStyles * sizeof(short));
-
- for(i=0; i<dp->numCurrentStyles; i++) {
-
- InitDocStyle(newTextStyles[i], &newStyle);
-
- newStyles[i] = FindDocStyle(dp, &newStyle);
-
- if(newStyles[i] == -1)
- newStyles[i] = AddDocTextStyle(dp, newTextStyles[i]);
-
- }
-
- HLock((Handle) dp->currentStyles);
-
- if(SetSelectionStyles(dp, dp->numCurrentStyles, *dp->currentStyles, newStyles))
- CalcPositionAndDraw(dp, dp->selection.startParaIndex);
-
- HUnlock((Handle) dp->currentStyles);
-
- DisposePtr((Ptr) newStyles);
-
- SetSelection(dp, dp->selection.startDocOffset, dp->selection.endDocOffset, false, dp->selection.endOfLine, false);
-
- } else
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- }
-
- void DocSetVariations(DocPtr dp, gxFont fontId, short numVariations, gxFontVariation * variations)
- {
- short ** newStyles;
-
- if(dp->numCurrentStyles != 0) {
-
- newStyles = (short **) NewHandle(dp->numCurrentStyles * sizeof(short));
-
- HLock((Handle) dp->currentStyles);
- HLock((Handle) newStyles);
-
- ModifyStyleVariations(dp, fontId, numVariations, variations, dp->numCurrentStyles, *dp->currentStyles, *newStyles);
-
- if(SetSelectionStyles(dp, dp->numCurrentStyles, *dp->currentStyles, *newStyles))
- CalcPositionAndDraw(dp, dp->selection.startParaIndex);
-
- HUnlock((Handle) dp->currentStyles);
- HUnlock((Handle) newStyles);
-
- DisposeHandle((Handle) newStyles);
-
- SetSelection(dp, dp->selection.startDocOffset, dp->selection.endDocOffset, false, dp->selection.endOfLine, false);
-
- } else
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- }
-
- void DocGetVariations(DocPtr dp, gxFont fontId, short * numInstancesPtr,
- short *** instanceSizesPtr, gxFontVariation **** instancesPtr)
- {
- if(dp->numCurrentStyles != 0) {
-
- HLock((Handle) dp->currentStyles);
-
- UnionStyleVariations(dp, dp->numCurrentStyles, *dp->currentStyles,
- fontId, numInstancesPtr, instanceSizesPtr, instancesPtr);
-
- HUnlock((Handle) dp->currentStyles);
-
-
- } else {
-
- *numInstancesPtr = 0;
- *instanceSizesPtr = nil;
- *instancesPtr = nil;
-
- }
-
- }
-
- void DocGetRunControls(DocPtr dp, gxRunControls * runControls, gxRunControls * mask)
- {
- if(dp->numCurrentStyles != 0) {
-
- HLock((Handle) dp->currentStyles);
-
- UnionStyleRunControls(dp, dp->numCurrentStyles, *dp->currentStyles, runControls, mask);
-
- HUnlock((Handle) dp->currentStyles);
-
- } else
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- }
-
- void DocSetRunControls(DocPtr dp, gxRunControls * runControls, gxRunControls * mask)
- {
- short ** newStyles;
-
- if(dp->numCurrentStyles != 0) {
-
- newStyles = (short **) NewHandle(dp->numCurrentStyles * sizeof(short));
-
- HLock((Handle) dp->currentStyles);
- HLock((Handle) newStyles);
-
- ModifyStyleRunControls(dp, runControls, mask, dp->numCurrentStyles, *dp->currentStyles, *newStyles);
-
- if(SetSelectionStyles(dp, dp->numCurrentStyles, *dp->currentStyles, *newStyles))
- CalcPositionAndDraw(dp, dp->selection.startParaIndex);
-
- HUnlock((Handle) dp->currentStyles);
- HUnlock((Handle) newStyles);
-
- DisposeHandle((Handle) newStyles);
-
- SetSelection(dp, dp->selection.startDocOffset, dp->selection.endDocOffset, false, dp->selection.endOfLine, false);
-
- } else
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- }
-
-
- void DocGetFontRunControls(DocPtr dp, gxFont fontID, gxRunControls * runControls, gxRunControls * mask)
- {
- if(dp->numCurrentStyles != 0) {
-
- HLock((Handle) dp->currentStyles);
-
- UnionFontRunControls(dp, dp->numCurrentStyles, *dp->currentStyles, fontID, runControls, mask);
-
- HUnlock((Handle) dp->currentStyles);
-
- } else
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- }
- void DocGetLayoutOptions(DocPtr dp, gxLayoutOptions * options, gxLayoutOptions * optionsMask)
- {
- ParaPtr pp;
- short startParagraphIndex;
- short endParagraphIndex;
- short paragraphIndex;
- short start;
- short end;
- Boolean firstTime;
-
- /* find the current selected paragraph */
-
- startParagraphIndex = dp->selection.startParaIndex;
- endParagraphIndex = dp->selection.endParaIndex;
-
- /* modify the selected paragraphs */
-
- HLock((Handle) dp->paragraphs);
-
- pp = *dp->paragraphs + startParagraphIndex;
- paragraphIndex = startParagraphIndex;
-
- start = dp->top;
- end = dp->top + (dp->viewRect.bottom - dp->viewRect.top);
-
- for(;paragraphIndex <= endParagraphIndex; paragraphIndex++, pp++) {
-
- firstTime = (paragraphIndex == startParagraphIndex);
-
- gxEditGetBitMaskOp(&pp->layoutOptions, options, optionsMask, sizeof(gxLayoutOptions), firstTime);
-
- }
-
- /* fix up the mask */
-
- if(~optionsMask->width)
- optionsMask->width = 0;
-
- if(~optionsMask->flush)
- optionsMask->flush = 0;
-
- if(~optionsMask->just)
- optionsMask->just = 0;
-
- if(~((long) optionsMask->baselineRec))
- optionsMask->baselineRec = nil;
-
- HUnlock((Handle) dp->paragraphs);
-
- }
-
- void DocSetLayoutOptions(DocPtr dp, gxLayoutOptions *options, gxLayoutOptions * optionsMask)
- {
- ParaPtr pp;
- LinePtr lp;
- short startParagraphIndex;
- short endParagraphIndex;
- short paragraphIndex;
- short lineIndex;
- short start;
- short end;
- gxLayoutOptions layoutOptions;
-
- /* find the current selected paragraph */
-
- startParagraphIndex = dp->selection.startParaIndex;
- endParagraphIndex = dp->selection.endParaIndex;
-
- /* modify the selected paragraphs */
-
- HLock((Handle) dp->paragraphs);
-
- pp = *dp->paragraphs + startParagraphIndex;
- paragraphIndex = startParagraphIndex;
-
- start = dp->top;
- end = dp->top + (dp->viewRect.bottom - dp->viewRect.top);
-
- for(;paragraphIndex <= endParagraphIndex; paragraphIndex++, pp++) {
-
- /* set the paragraph options */
-
- if(gxEditSetBitMaskOp(options, &pp->layoutOptions, optionsMask, sizeof(gxLayoutOptions))) {
-
- pp->width = FixedToInt(pp->layoutOptions.width);
-
- /* change all of the layout options of the lines */
-
- HLock((Handle) pp->lines);
-
- lp = *pp->lines;
-
- for(lineIndex=0; lineIndex < pp->numLines; lineIndex++, lp++) {
-
- if(lineIndex == pp->numLines - 1) {
- layoutOptions = pp->layoutOptions;
- layoutOptions.just = gxNoJustification;
- GXSetLayout(lp->layout, 0, nil, nil, 0, nil, nil, 0, nil, nil, &layoutOptions, nil);
- } else
- GXSetLayout(lp->layout, 0, nil, nil, 0, nil, nil, 0, nil, nil, &pp->layoutOptions, nil);
-
- lp->drawn = false;
- }
-
- HUnlock((Handle) pp->lines);
-
- /* now redraw the paragraph if it is displayed on the screen */
-
- if(pp->start + GetParagraphHeight(dp, pp) >= start || pp->start < end)
- DrawParagraph(dp, pp, start, end);
- }
-
- }
-
- gxEditSetBitMaskOp(options, &dp->currentLayoutOptions, optionsMask, sizeof(gxLayoutOptions));
-
- HUnlock((Handle) dp->paragraphs);
-
- }
-
- void DocPrint(DocPtr dp, gxJob printJob)
- {
- short numPages;
- long ** pageStarts;
- short page;
- OSErr err;
- gxViewPort aViewPort;
- gxShape picture;
-
- aViewPort = dp->docViewPort;
-
- CalcPrintPages(dp, printJob, &numPages, &pageStarts);
-
- /* document title should be used !!! */
-
- GXStartJob(printJob, "\pGX Edit Doc", numPages);
-
- if((err = GXGetJobError(printJob)) != noErr)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- for(page=0; page<numPages; page++) {
-
- picture = GetAPage(dp, (*pageStarts)[page]);
-
- GXPrintPage(printJob, page+1, GXGetJobFormat((gxJob) printJob, 1), picture);
-
- if((err = GXGetJobError((gxJob) printJob)) != noErr)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- GXDisposeShape(picture);
-
- }
-
- GXFinishJob(printJob);
-
- if((err =GXGetJobError(printJob)) != noErr)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- DisposeHandle((Handle) pageStarts);
- }
-
- void DocCopy(DocPtr dp)
- {
-
- Copy(dp);
-
- }
-
-
- void DocPaste(DocPtr dp)
- {
-
- Paste(dp);
-
- /* reflow the document */
-
- while(DocReflow(dp)) ;
-
- CheckCaretVisibility(dp);
-
- Draw(dp, 0, dp->viewHeight);
-
- }
-
- long DocGetScrapLen(DocPtr dp)
- {
- return(dp->scrap.numText);
- }
-
- long DocGetSelectionLen(DocPtr dp)
- {
- return(dp->selection.endDocOffset - dp->selection.startDocOffset);
- }
-
- long DocGetTextLen(DocPtr dp)
- {
- return(dp->numText);
- }
-
- Boolean DocIdle(DocPtr dp)
- {
- Boolean modified;
-
- dp->currentTime = TickCount();
-
- BlinkCursor(dp);
-
- if(modified = DocReflow(dp)) {
-
- CheckCaretVisibility(dp);
-
- Draw(dp, 0, dp->viewHeight);
-
- }
-
- return(modified);
-
- }
-
- void DocSetVerticalText(DocPtr dp, Boolean enable)
- {
- ParaPtr pp;
- StylePtr sp;
- LinePtr lp;
- short i, j;
- gxTextAttribute attributes;
-
- if(dp->verticalText != enable) {
-
- dp->verticalText = enable;
-
- if(dp->verticalText) {
- dp->lineWidth = dp->viewRect.bottom - dp->viewRect.top - dp->leftMargin - dp->rightMargin;
- dp->viewHeight = dp->viewRect.right - dp->viewRect.left;
- } else {
- dp->lineWidth = dp->viewRect.right - dp->viewRect.left - dp->leftMargin - dp->rightMargin;
- dp->viewHeight = dp->viewRect.bottom - dp->viewRect.top;
- }
-
- /* set all paragraph widths to the new line width value */
-
- pp = *dp->paragraphs;
-
- for(i=0; i<dp->numParagraphs; i++, pp++) {
-
- pp->width = dp->lineWidth;
- pp->layoutOptions.width = ff(pp->width);
-
- if(pp->numLines) {
-
- pp->reflow = true;
- (*pp->lines)[0].reflow = true;
-
- }
- }
-
- /* change all existing styles to have the correct text attribute */
-
- sp = *dp->styles;
- for(i=0; i<dp->numStyles;i++,sp++) {
- attributes = GXGetStyleTextAttributes(sp->textStyle);
-
- if(enable)
- attributes |= gxVerticalText;
- else
- attributes &= ~gxVerticalText;
-
- GXSetStyleTextAttributes(sp->textStyle, attributes);
- }
-
- /* mark everything dirty */
-
- for(i=0, pp = *dp->paragraphs; i<dp->numParagraphs;i++, pp++) {
- for(j=0, lp = *pp->lines; j<pp->numLines; j++, lp++)
- lp->dirty = true;
- pp->dirty = true;
- }
- dp->dirty = true;
-
- /* mark the entire document as not drawn */
- dp->drawn = false;
-
- /* make sure we clear the entire document white area */
- if(dp->verticalText)
- dp->bottomClear = dp->viewRect.left;
- else
- dp->bottomClear = dp->viewRect.bottom;
-
- }
-
- }
-
- void DocGetVerticalText(DocPtr dp, Boolean * enable)
- {
- *enable = dp->verticalText;
- }
-
- void DocGetSelectionEncoding(DocPtr dp, gxFontPlatform * platformPtr, gxFontScript * scriptPtr, gxFontLanguage * languagePtr)
- {
- short i;
- gxFontPlatform platform;
- gxFontScript script;
- gxFontLanguage language;
- gxStyle style;
- gxFontPlatform nextPlatform;
- gxFontScript nextScript;
- gxFontLanguage nextLanguage;
-
- if(!dp->numCurrentStyles) {
- gxEditPostError(dp, gx_edit_internal_fatal_error);
- return;
- }
-
- style = GetDocStyle(dp, (*dp->currentStyles)[0])->textStyle;
-
- platform = GXGetStyleEncoding(style, &script, &language);
-
- for(i=0; i < dp->numCurrentStyles; i++) {
-
- style = GetDocStyle(dp, (*dp->currentStyles)[i])->textStyle;
-
- nextPlatform = GXGetStyleEncoding(style, &nextScript, &nextLanguage);
-
- if(nextPlatform != platform)
- platform = gxNoPlatform;
-
- if(nextScript != script)
- script = gxNoScript;
-
- if(nextLanguage != language)
- language = gxNoLanguage;
-
- }
-
- if(platformPtr != nil) *platformPtr = platform;
- if(scriptPtr != nil) *scriptPtr = script;
- if(languagePtr != nil) *languagePtr = language;
-
- }
-
- void DocSetSelectionEncoding(DocPtr dp, gxFontPlatform platform, gxFontScript script, gxFontLanguage language)
- {
- short * newStyles;
- short i;
-
- if(dp->numCurrentStyles != 0) {
-
- newStyles = (short *) NewPtr(dp->numCurrentStyles * sizeof(short));
-
- HLock((Handle) dp->currentStyles);
-
- for(i=0; i<dp->numCurrentStyles; i++)
- newStyles[i] = SetDocStyleEncoding(dp, (*dp->currentStyles)[i], platform, script, language);
-
- if(SetSelectionStyles(dp, dp->numCurrentStyles, *dp->currentStyles, newStyles))
- CalcPositionAndDraw(dp, dp->selection.startParaIndex);
-
- HUnlock((Handle) dp->currentStyles);
-
- DisposePtr((Ptr) newStyles);
-
- SetSelection(dp, dp->selection.startDocOffset, dp->selection.endDocOffset, false, dp->selection.endOfLine, false);
-
- } else
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- }
-
- static void CalcPrintPages(DocPtr dp, gxJob printJob, short * numPagesPtr, long *** pageStartsPtr)
- {
- short numPages;
- long ** pageStarts;
- ParaPtr pp;
- LinePtr lp;
- short paragraphIndex;
- short lineIndex;
- short top;
- short bottom;
- long docOffset;
- gxFormat format;
- gxRectangle pageSize;
- gxRectangle paperSize;
-
- numPages = 0;
- pageStarts = (long **) NewHandle(0);
-
- /* calculate the page dimensions */
-
- format = GXGetJobFormat((gxJob) printJob, 1);
- GXGetFormatDimensions(format, &pageSize, &paperSize);
-
- dp->pageTop = FixedToInt(paperSize.top) + kPrintTopMargin;
- dp->pageLeft = FixedToInt(paperSize.left) + kPrintLeftMargin;
- dp->pageBottom = FixedToInt(paperSize.bottom) - kPrintBottomMargin;
- dp->pageRight = FixedToInt(paperSize.right) - kPrintRightMargin;
-
- HLock((Handle) dp->paragraphs);
-
- pp = *dp->paragraphs;
-
- if(dp->verticalText) {
-
- /* layout left to right for now, we only need to see what layous fit */
-
- top = dp->pageLeft;
- bottom = dp->pageRight;
-
- } else {
- top = dp->pageTop;
- bottom = dp->pageBottom;
- }
-
- docOffset = 0;
-
- for(paragraphIndex = 0; paragraphIndex < dp->numParagraphs; paragraphIndex++, pp++) {
-
- HLock((Handle) pp->lines);
-
- lp = *pp->lines;
-
- for(lineIndex = 0; lineIndex < pp->numLines; lineIndex++, lp++) {
-
- if(top + GetLineHeight(dp, pp, lp) > bottom) {
-
- PtrAndHand((Ptr) &docOffset, (Handle) pageStarts, sizeof(long));
- docOffset = lp->paraOffset + pp->docOffset;
- top = dp->pageTop;
- numPages++;
-
- }
-
- top += lp->height;
-
- }
-
- HUnlock((Handle) pp->lines);
-
- }
-
- HUnlock((Handle) dp->paragraphs);
-
- PtrAndHand((Ptr) &docOffset, (Handle) pageStarts, sizeof(long));
- numPages++;
-
- *pageStartsPtr = pageStarts;
- *numPagesPtr = numPages;
- }
-
- static gxShape GetAPage(DocPtr dp, long docOffset)
- {
- ParaPtr pp;
- LinePtr lp;
- gxShape picture;
- short top;
- short bottom;
- short left;
- short right;
- fixed fixedLeft;
- fixed fixedTop;
- short paragraphIndex;
- short lineIndex;
- short paraOffset;
- long numLayouts;
- void ** layouts;
-
- layouts = (void **) NewHandle(0);
- numLayouts = 0;
-
- HLock((Handle) dp->paragraphs);
-
- pp = *dp->paragraphs;
-
- for(paragraphIndex = 0; paragraphIndex < dp->numParagraphs; paragraphIndex++, pp++)
- if(pp->docOffset + pp->numText > docOffset)
- break;
-
- if(paragraphIndex == dp->numParagraphs)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- HLock((Handle) pp->lines);
-
- lp = *pp->lines;
- paraOffset = docOffset - pp->docOffset;
-
- for(lineIndex = 0; lineIndex < pp->numLines; lineIndex++, lp++)
- if(lp->paraOffset + lp->numText > paraOffset)
- break;
-
- if(lineIndex == pp->numLines)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- if(dp->verticalText) {
-
- left = dp->pageLeft;
- right = dp->pageRight;
-
- fixedTop = ff(dp->pageTop);
-
- while(right - GetLineHeight(dp, pp, lp) > left) {
-
- fixedLeft = ff(right - lp->ascent);
-
- if(lp->layoutPos.x != fixedLeft || lp->layoutPos.y != fixedTop) {
-
- GXMoveShapeTo((gxShape) lp->layout, fixedLeft, fixedTop);
-
- lp->layoutPos.x = fixedLeft;
- lp->layoutPos.y = fixedTop;
-
- }
-
- PtrAndHand((Ptr) &lp->layout, (Handle) layouts, sizeof(void *));
-
- right -= lp->height;
-
- lineIndex++;
- lp++;
-
- if(lineIndex == pp->numLines) {
-
- paragraphIndex++;
-
- if(paragraphIndex == dp->numParagraphs)
- break;
-
- HUnlock((Handle) pp->lines);
-
- pp++;
-
- HLock((Handle) pp->lines);
-
- lp = *pp->lines;
- lineIndex = 0;
-
- }
-
- }
-
- } else {
-
- top = dp->pageTop;
- bottom = dp->pageBottom;
-
- fixedLeft = ff(dp->pageLeft);
-
- while(top + GetLineHeight(dp, pp, lp) < bottom) {
-
- fixedTop = ff(top + lp->ascent);
-
- if(lp->layoutPos.x != fixedLeft || lp->layoutPos.y != fixedTop) {
-
- GXMoveShapeTo((gxShape) lp->layout, fixedLeft, fixedTop);
-
- lp->layoutPos.x = fixedLeft;
- lp->layoutPos.y = fixedTop;
-
- }
-
- PtrAndHand((Ptr) &lp->layout, (Handle) layouts, sizeof(void *));
-
- top += lp->height;
-
- lineIndex++;
- lp++;
-
- if(lineIndex == pp->numLines) {
-
- paragraphIndex++;
-
- if(paragraphIndex == dp->numParagraphs)
- break;
-
- HUnlock((Handle) pp->lines);
-
- pp++;
-
- HLock((Handle) pp->lines);
-
- lp = *pp->lines;
- lineIndex = 0;
-
- }
-
- }
- }
-
- HUnlock((Handle) pp->lines);
-
- HUnlock((Handle) dp->paragraphs);
-
- numLayouts = GetHandleSize((Handle) layouts) / sizeof(void *);
-
- HLock((Handle) layouts);
-
- picture = GXNewPicture(numLayouts, *layouts, nil, nil, nil);
-
- HUnlock((Handle) layouts);
-
- DisposeHandle((Handle) layouts);
-
- return(picture);
-
- }
-
- static void CalcOffsets(DocPtr dp, short paragraphIndex)
- {
- ParaPtr pp;
- short docOffset;
-
- if(paragraphIndex < 0 || paragraphIndex > dp->numParagraphs)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- pp = *dp->paragraphs + paragraphIndex;
-
- if(paragraphIndex == 0)
- pp->docOffset = 0;
- else {
- paragraphIndex--;
- pp--;
- }
-
- docOffset = pp->docOffset + pp->numText;
-
- paragraphIndex++;
- pp++;
-
- for(;paragraphIndex < dp->numParagraphs; paragraphIndex++, pp++) {
- pp->docOffset = docOffset;
- docOffset += pp->numText;
- }
-
- dp->numText = docOffset;
-
- }
-
- static void CalcStarts(DocPtr dp, short paragraphIndex)
- {
- ParaPtr pp;
- long start;
-
- if(paragraphIndex < 0 || paragraphIndex > dp->numParagraphs)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- HLock((Handle) dp->paragraphs);
-
- pp = *dp->paragraphs + paragraphIndex;
-
- if(paragraphIndex == 0) {
-
- if(pp->start != 0)
- pp->drawn = false;
-
- pp->start = 0;
-
- } else {
-
- paragraphIndex--;
- pp--;
- }
-
- start = pp->start + GetParagraphHeight(dp, pp);
-
- paragraphIndex++;
- pp++;
-
- for(;paragraphIndex < dp->numParagraphs; paragraphIndex++, pp++) {
-
- if(pp->start != start)
- pp->drawn = false; /* the paragraph has moved -- redraw */
-
- pp->start = start;
-
- start += GetParagraphHeight(dp, pp);
-
- }
-
- HUnlock((Handle) dp->paragraphs);
-
- dp->length = start;
- dp->dirty = false;
-
- DocSetMaxTop(dp);
-
- }
-
- static void InsertNewParagraph(DocPtr dp, short paragraphIndex, short paragraphOffset)
- {
- ParaRec newPara;
- ParaPtr pp;
- long size;
-
- HLock((Handle) dp->paragraphs);
-
- pp = *dp->paragraphs + paragraphIndex;
-
- SplitParagraph(dp, pp, paragraphOffset, &newPara);
-
- HUnlock((Handle) dp->paragraphs);
-
- dp->numParagraphs++;
-
- SetHandleSize((Handle) dp->paragraphs, dp->numParagraphs * sizeof(ParaRec));
-
- size = sizeof(ParaRec) * (dp->numParagraphs - paragraphIndex - 2);
-
- BlockMove((Ptr) (*dp->paragraphs + paragraphIndex + 1),
- (Ptr) (*dp->paragraphs + paragraphIndex + 2), size);
-
- BlockMove((Ptr) &newPara, (Ptr) (*dp->paragraphs + paragraphIndex + 1), sizeof(ParaRec));
-
- }
-
- void DocSetMaxTop(DocPtr dp)
- {
- short dv;
-
- dp->maxTop = DocHeight(dp) - dp->viewHeight;
-
- if(dp->maxTop < 0)
- dp->maxTop = 0;
-
- if(dp->top > dp->maxTop) {
-
- dv = dp->top - dp->maxTop;
-
- DocScroll(dp, dv);
-
- }
- }
-
- void DocProof(DocPtr dp, GXEditProofPtr proof)
- {
- long startParaIndex;
- long pointSize;
- ReplacementRec replacements;
- long startOffset;
-
- if(dp->selection.startDocOffset == dp->selection.endDocOffset)
- return; /* nothing to proof */
-
- Copy(dp);
- Clear(dp);
-
- startParaIndex = dp->selection.startParaIndex;
-
- /* generate the text to waterfall */
-
- startOffset = dp->selection.startDocOffset;
-
- NewReplacements(dp, proof, &replacements);
-
- do {
-
- DoReplacements(&replacements);
-
- Paste(dp);
-
- } while(!TestReplacements(&replacements));
-
- SetSelection(dp, startOffset, dp->selection.endDocOffset, false, dp->selection.endOfLine, false);
-
- Copy(dp);
- Clear(dp);
-
- /* generate the waterfall */
-
- pointSize = proof->startPointSize;
-
- while(pointSize <= proof->endPointSize) {
-
- Paste(dp);
-
- SetSelection(dp, dp->selection.endDocOffset - dp->scrap.numText, dp->selection.endDocOffset, false, dp->selection.endOfLine, false);
-
- DocSetTextSize(dp, pointSize);
-
- SetSelection(dp, dp->selection.endDocOffset, dp->selection.endDocOffset, false, dp->selection.endOfLine, false);
-
- pointSize += proof->stepPointSize;
- }
-
- DisposeReplacements( &replacements);
-
- CalcOffsets(dp, startParaIndex);
-
- dp->dirty = true; /* CalcStarts(dp, startParaIndex); */
-
- /* reflow the document */
-
- while(DocReflow(dp)) ;
-
- CheckCaretVisibility(dp);
-
- Draw(dp, 0, dp->viewHeight);
-
- }
-
- void DocActivate(DocPtr dp, Boolean activate)
- {
-
- if(activate) {
- gxEditScrapFromDesk(dp);
- } else {
- gxEditScrapToDesk(dp);
- }
-
- }
-
- void DocSetEncoding(DocPtr dp, gxFontPlatform platform, gxFontScript script, gxFontLanguage language)
- {
- dp->currentPlatform = platform;
- dp->currentScript = script;
- dp->currentLanguage = language;
- }
-
- static void InitRunControl(gxRunControls * runControl)
- {
-
- runControl->flags = 0; /* all off id the default state */
- runControl->beforeWithStreamShift = ff(0);
- runControl->afterWithStreamShift = ff(0);
- runControl->crossStreamShift = ff(0);
- runControl->imposedWidth = ff(0);
- runControl->track = gxNoTracking;
- runControl->hangingInhibitFactor = fract1;
- runControl->kerningInhibitFactor = fract1;
- runControl->decompositionAdjustmentFactor = ff(0);
- runControl->baselineType = 0; /* roman baseline */
-
- }
-
- static void BlinkCursor(DocPtr dp)
- {
- if(dp->selection.startDocOffset != dp->selection.endDocOffset)
- return; /* selection range is not a cursor */
-
- /* code to blink cursor */
- }
-
- Boolean DocReflow(DocPtr dp)
- {
- ParaPtr pp;
- short paragraphIndex;
-
- /* try to find a paragraph that needs to be reflowed */
-
- HLock((Handle) dp->paragraphs);
-
- pp = *dp->paragraphs;
-
- for(paragraphIndex=0; paragraphIndex < dp->numParagraphs; paragraphIndex++, pp++)
- if(pp->reflow) {
-
- ReflowParagraph(dp, pp);
-
- HUnlock((Handle) dp->paragraphs);
-
- CalcOffsets(dp, paragraphIndex);
-
- dp->dirty = true; /* CalcStarts(dp, paragraphIndex); */
-
- return(true);
- }
-
- HUnlock((Handle) dp->paragraphs);
- }
-
- static void CalcPositionAndDraw(DocPtr dp,short startIndex)
- {
- /* calculate starts and offsets -- set document height */
- CalcOffsets(dp, startIndex);
- dp->dirty = true; /* CalcStarts(dp, startIndex); */
- CheckCaretVisibility(dp);
- Draw(dp, 0, dp->viewHeight);
- }
-
- static void Position(DocPtr dp, long docOffset, long * start, long * end)
- {
- ParaPtr pp;
- short paragraphIndex;
- short paragraphOffset;
-
- if(dp->dirty) /* we are using paragraph starts, make sure document is not dirty */
- CalcStarts(dp, 0);
-
- GetParagraphIndexAndOffset(dp, docOffset, ¶graphIndex, ¶graphOffset, false);
-
- HLock((Handle) dp->paragraphs);
-
- pp = *dp->paragraphs + paragraphIndex;
-
- ParagraphPosition(dp, pp, paragraphOffset, start, end);
-
- *start += pp->start;
- *end += pp->start;
-
- HUnlock((Handle) dp->paragraphs);
-
- }
-
- static void Draw(DocPtr dp, long start, long end)
- {
- ParaPtr pp;
- short paragraphIndex;
-
- if(start > end)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- if(start < 0)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- if(end < 0)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- if(start > dp->viewHeight)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- if(end > dp->viewHeight)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- if(dp->dirty) /* we are using paragraph starts, make sure document is not dirty */
- CalcStarts(dp, 0);
-
- HLock((Handle) dp->paragraphs);
-
- /* map the view area coords to doc coords */
-
- start += dp->top;
- end += dp->top;
-
- /* loop through all of the paragraphs, draw paragraphs that fall in the range */
-
- /* this loop should be optimized in the future */
-
- pp = *dp->paragraphs;
-
- for(paragraphIndex=0; paragraphIndex < dp->numParagraphs; pp++, paragraphIndex++) {
-
- if((pp->start + GetParagraphHeight(dp, pp)) >= start && (pp->start < end)) {
-
- DrawParagraph(dp, pp, start, end);
-
- } else {
-
- pp->drawn = false;
-
- }
-
- }
-
- /* erase from the last paragraph to end of view if necessary */
-
-
- if(paragraphIndex == dp->numParagraphs)
- DoEraseToEndOfView(dp);
-
-
- dp->drawn = true;
-
- HUnlock((Handle) dp->paragraphs);
-
- }
-
- static void HitTest(DocPtr dp, Point where, long * docOffsetPtr, Boolean * endOfLinePtr, Boolean extend)
- {
- ParaPtr pp;
- long docOffset;
- short paraIndex;
- short paraOffset;
- Boolean endOfLine;
-
- if(dp->dirty) /* we are using paragraph starts, make sure document is not dirty */
- CalcStarts(dp, 0);
-
- if(dp->verticalText) {
-
- if(where.h > dp->viewRect.right)
- where.h = dp->viewRect.right;
-
- if(where.h < dp->viewRect.left)
- where.h = dp->viewRect.left;
-
- where.h = dp->viewRect.right - where.h;
-
- where.v -= dp->viewRect.top + dp->leftMargin;
-
- } else {
-
- if(where.v < dp->viewRect.top)
- where.v = dp->viewRect.top;
-
- if(where.v > dp->viewRect.bottom)
- where.v = dp->viewRect.bottom;
-
- where.v -= dp->viewRect.top;
-
- where.h -= dp->viewRect.left + dp->leftMargin;
-
- where.v += dp->top;
-
- }
-
- HLock((Handle) dp->paragraphs);
-
- /* find the paragraph and hit test paragraph */
-
- pp = *dp->paragraphs;
- docOffset = 0;
-
- if(dp->verticalText) {
- for(paraIndex=0; paraIndex < dp->numParagraphs; paraIndex++,pp++)
- if(where.h >= pp->start && where.h < (pp->start + GetParagraphHeight(dp, pp))) {
-
- where.h -= pp->start;
-
- HitTestParagraph(dp, pp, where, ¶Offset, &endOfLine);
-
- if(!extend && paraOffset == pp->numText) {
- paraOffset--;
- endOfLine = false;
- }
-
- docOffset = paraOffset + pp->docOffset;
- break;
-
- }
- } else {
- for(paraIndex=0; paraIndex < dp->numParagraphs; paraIndex++,pp++)
- if(where.v >= pp->start && where.v < (pp->start + GetParagraphHeight(dp, pp))) {
-
- where.v -= pp->start;
-
- HitTestParagraph(dp, pp, where, ¶Offset, &endOfLine);
-
- if(!extend && paraOffset == pp->numText) {
- paraOffset--;
- endOfLine = false;
- }
-
- docOffset = paraOffset + pp->docOffset;
- break;
-
- }
- }
-
- if(paraIndex == dp->numParagraphs && dp->numParagraphs != 0)
- docOffset = (pp-1)->docOffset + (pp-1)->numText;
-
- HUnlock((Handle) dp->paragraphs);
-
- *docOffsetPtr = docOffset;
- *endOfLinePtr = endOfLine;
-
- }
-
- static void Insert(DocPtr dp, void * text, short startNumText, short styleIndex)
- {
- short paragraphIndex, paragraphOffset;
- ParaPtr pp;
- short numParaText;
- char * ptr;
- short startIndex;
- short startOffset;
- short newParagraphs;
- long docOffset;
- short numText;
- StylePtr style;
- Boolean setEmptyStyle;
-
- Clear(dp);
-
- if(dp->numCurrentStyles == 0)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- /* find the paragraph index and offset from the current selection start */
-
- paragraphIndex = dp->selection.startParaIndex;
- paragraphOffset = dp->selection.startParaOffset;
-
- numText = startNumText;
-
- if(numText == 0)
- return;
-
- HLock((Handle) dp->paragraphs);
-
- startIndex = paragraphIndex;
- startOffset = paragraphOffset;
- newParagraphs = 0;
-
- style = GetDocStyle(dp, styleIndex);
-
- if(style->platform != gxGlyphPlatform) {
-
- /* insert all characters up to the newline character */
-
- for(numParaText=0, ptr=(char *) text; numParaText<numText; numParaText++, ptr++)
- if(*ptr == '\r')
- break;
-
- } else
- numParaText = numText;
-
- if(numParaText) {
-
- pp = *dp->paragraphs + paragraphIndex;
-
- InsertParagraphText(dp, pp, paragraphOffset, text, numParaText, styleIndex);
-
- numText -= numParaText;
- text = (void *) ((long) text + numParaText );
- paragraphOffset += numParaText;
-
- }
-
- /* now add new paragraphs as appropriate */
-
- while(numText) {
-
- text = (void *) ((long) text + 1);
- numText--; /* skip past newline */
-
- for(numParaText=0, ptr=(char *) text; numParaText<numText; numParaText++, ptr++)
- if(*ptr == '\r')
- break;
-
- HUnlock((Handle) dp->paragraphs);
-
- InsertNewParagraph(dp, paragraphIndex, paragraphOffset);
-
- newParagraphs++;
-
- paragraphIndex++;
- paragraphOffset = 0;
-
- HLock((Handle) dp->paragraphs);
-
- if(numParaText) {
-
- pp = *dp->paragraphs + paragraphIndex;
-
- InsertParagraphText(dp, pp, 0, text, numParaText, styleIndex);
-
- numText -= numParaText;
- text = (void *) ((long) text + numParaText);
- paragraphOffset += numParaText;
-
- }
-
-
- }
-
- HUnlock((Handle) dp->paragraphs);
-
- /* calculate starts and offsets -- set document height */
-
- CalcOffsets(dp, startIndex);
-
- dp->dirty = true; /* CalcStarts(dp, startIndex); */
-
- /* update the current selection */
-
- docOffset = dp->selection.startDocOffset + startNumText;
-
- /* should we set the empty style? */
- setEmptyStyle = (dp->selection.startDocOffset == dp->selection.endDocOffset);
-
- SetSelection(dp, docOffset, docOffset, setEmptyStyle, false, true);
-
- }
-
- static void Clear(DocPtr dp)
- {
- ParaPtr pp;
- long start;
- long end;
- short paragraphIndex;
- short paragraphOffset;
- short numText;
- long size;
- Boolean needToJoin;
- short paraText;
- short index;
- short startIndex;
-
- if(dp->selection.startDocOffset == dp->selection.endDocOffset)
- return; /* nothing to clear */
-
- /* make sure we don't clear the entire docuemnt -- leave at least one empty paragraph */
-
- if(dp->selection.startDocOffset == 0 && dp->selection.endDocOffset == dp->numText)
- dp->selection.endDocOffset--;
-
- start = dp->selection.startDocOffset;
- end = dp->selection.endDocOffset;
-
- numText = end - start;
-
- /* find out where to start */
-
- HLock((Handle) dp->paragraphs);
-
- GetParagraphIndexAndOffset(dp, start, ¶graphIndex, ¶graphOffset, false);
-
- startIndex = index = paragraphIndex;
-
- needToJoin = false;
-
- if(paragraphOffset != 0) {
-
- pp = *dp->paragraphs + index;
-
- paraText = pp->numText - paragraphOffset;
-
- if(numText < paraText)
- paraText = numText;
- else {
- paraText--; /* don't delete '\r' */
- needToJoin = true;
- }
-
- ParagraphClear(dp, pp, paragraphOffset, paraText);
-
- numText -= paraText;
-
- if(needToJoin)
- numText--; /* the '\r' will be removed when the paragraphs are joined */
-
- index++;
-
- }
-
- while(numText) {
-
- pp = *dp->paragraphs + index;
-
- if(numText >= pp->numText) {
-
- numText -= pp->numText;
-
- gxEditDisposeParagraph(dp, pp);
-
- dp->numParagraphs--;
-
- size = (dp->numParagraphs - index) * sizeof(ParaRec);
- BlockMove((Ptr) (pp+1), (Ptr) pp, size);
-
- HUnlock((Handle) dp->paragraphs);
-
- size = dp->numParagraphs * sizeof(ParaRec);
- SetHandleSize((Handle) dp->paragraphs, size);
-
- HLock((Handle) dp->paragraphs);
-
- } else {
-
- ParagraphClear(dp, pp, 0, numText);
-
- numText = 0;
-
-
-
- }
-
- }
-
- if(needToJoin && index != dp->numParagraphs) {
-
- pp = *dp->paragraphs + index;
-
- JoinParagraphs(dp, pp-1, pp);
-
- dp->numParagraphs--;
-
- size = (dp->numParagraphs - index) * sizeof(ParaRec);
- BlockMove((Ptr) (pp+1), (Ptr) pp, size);
-
- HUnlock((Handle) dp->paragraphs);
-
- size = dp->numParagraphs * sizeof(ParaRec);
- SetHandleSize((Handle) dp->paragraphs, size);
-
- HLock((Handle) dp->paragraphs);
-
- }
-
- HUnlock((Handle) dp->paragraphs);
-
- CalcOffsets(dp, paragraphIndex);
-
- dp->dirty = true; /* CalcStarts(dp, paragraphIndex); */
-
- SetSelection(dp, dp->selection.startDocOffset, dp->selection.startDocOffset, false, false, true);
-
- }
-
- static void CheckCaretVisibility(DocPtr dp)
- {
- long start, end;
- short dv;
-
- /* scroll the screen if the caret is not in the visible area */
-
- Position(dp, dp->selection.startDocOffset, &start, &end);
-
- if(end > dp->top + dp->viewHeight) {
-
- dv = dp->top - (end - dp->viewHeight);
-
- DocScroll(dp, dv);
-
- }
-
- }
-
- static void Paste(DocPtr dp)
- {
- NewRunPtr rp;
- short runIndex;
-
- if(dp->scrap.numRuns == 0)
- return; /* no scrap text to paste */
-
- HLock((Handle) dp->scrap.runs);
-
- rp = *(dp->scrap.runs);
-
- for(runIndex=0; runIndex < dp->scrap.numRuns; runIndex++, rp++) {
-
- HLock((Handle) rp->text);
-
- Insert(dp, *rp->text, rp->numText, rp->styleIndex);
-
- HUnlock((Handle) rp->text);
- }
-
- HUnlock((Handle) dp->scrap.runs);
- }
-
- static void Copy(DocPtr dp)
- {
- ParaPtr pp;
- NewRunPtr rp;
- short paragraphIndex;
- short runIndex;
- long start;
- long numText;
- NewRunRec run;
- long size;
- ScrapPtr scrap;
- short numAppendText;
-
- start = dp->selection.startDocOffset;
- numText = dp->selection.endDocOffset - start;
-
- if(!numText)
- return; /* nothing to copy */
-
- scrap = &dp->scrap;
-
- /* clear out the current scrap */
-
- gxEditEmptyScrap(dp);
-
- /* set scrap length while we have the correct text count available */
-
- scrap->numText = numText;
-
- /* get to the start of the selection and make a copy of the first partial run,
- all intermediate runs and the partial last run */
-
- HLock((Handle) dp->paragraphs);
-
- pp = *dp->paragraphs;
-
- for(paragraphIndex=0; paragraphIndex < dp->numParagraphs; paragraphIndex++, pp++)
- if(start < (pp->docOffset + pp->numText))
- break;
-
- if(paragraphIndex == dp->numParagraphs)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- start -= pp->docOffset;
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs;
-
- for(runIndex = 0; runIndex < pp->numRuns; runIndex++, rp++)
- if(start < (rp->paraOffset + rp->numText))
- break;
-
- if(runIndex == pp->numRuns)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- start -= rp->paraOffset;
-
- /* grab the text */
-
- run.styleIndex = rp->styleIndex;
-
- IncrementDocStyleRefCount(dp, run.styleIndex);
-
- run.numText = rp->numText - start;
-
- if(run.numText > numText)
- run.numText = numText;
-
- size = run.numText;
- run.text = (void **) NewHandle(size);
-
- BlockMove((Ptr) ((long) *rp->text + (start)), (Ptr) *run.text, size);
-
- PtrAndHand((Ptr) &run, (Handle) scrap->runs, sizeof(NewRunRec));
- scrap->numRuns++;
-
- numText -= run.numText;
-
- runIndex++;
- rp++;
-
- while(numText) {
-
- if(runIndex == pp->numRuns) {
-
- HUnlock((Handle) pp->runs);
-
- paragraphIndex++;
- pp++;
-
- if(paragraphIndex == dp->numParagraphs)
- gxEditPostError(dp, gx_edit_internal_fatal_error);
-
- HLock((Handle) pp->runs);
-
- rp = *pp->runs;
- runIndex = 0;
-
- }
-
- if(rp->styleIndex == run.styleIndex) {
-
- /* just add the text to the last scrap run */
-
- numAppendText = rp->numText;
-
- if(numAppendText > numText)
- numAppendText = numText;
-
- size = (run.numText + numAppendText);
- SetHandleSize((Handle) run.text, size);
-
- size = numAppendText;
- BlockMove((Ptr) *rp->text, (Ptr) ((long) *run.text + (run.numText)), size);
-
- run.numText += numAppendText;
-
- BlockMove((Ptr) &run, (Ptr) (*scrap->runs + scrap->numRuns - 1), sizeof(NewRunRec));
-
- numText -= numAppendText;
-
- } else {
-
- /* add a new run to the scrap */
-
- run.styleIndex = rp->styleIndex;
-
- IncrementDocStyleRefCount(dp, run.styleIndex);
-
- run.numText = rp->numText;
-
- if(run.numText > numText)
- run.numText = numText;
-
- size = run.numText;
- run.text = (void **) NewHandle(size);
-
- BlockMove((Ptr) *rp->text, (Ptr) *run.text, size);
-
- PtrAndHand((Ptr) &run, (Handle) scrap->runs, sizeof(NewRunRec));
- scrap->numRuns++;
-
- numText -= run.numText;
-
- }
-
- if(numText == 0)
- break;
-
- runIndex++;
- rp++;
-
- }
-
- HUnlock((Handle) pp->runs);
- HUnlock((Handle) dp->paragraphs);
-
- }
-
- static void DoEraseToEndOfView(DocPtr dp)
- {
- Rect rect;
- gxRectangle aRect;
- gxShape eraser;
- ParaPtr pp;
-
- pp = *dp->paragraphs + dp->numParagraphs - 1;
-
- if(dp->verticalText) {
-
- rect.top = dp->viewRect.top;
- rect.bottom = dp->viewRect.bottom;
- rect.right = dp->viewRect.right - (pp->start + GetParagraphHeight(dp, pp) - dp->top);
- rect.left = dp->bottomClear;
-
- if(rect.right > rect.left) {
-
- aRect.top = ff(rect.top);
- aRect.left = ff(rect.left);
- aRect.bottom = ff(rect.bottom);
- aRect.right = ff(rect.right);
-
- eraser = GXNewRectangle(&aRect);
-
- /* This ignores is needed because we do not keep track of the current
- clip of the view port. Thus, we will often set the clip to the same rect
- which generates a notice*/
-
- #ifdef debugging
- GXIgnoreGraphicsNotice(clip_already_set);
- #endif
-
- GXSetViewPortClip(dp->docViewPort, eraser);
-
- #ifdef debugging
- GXPopGraphicsNotice();
- #endif
-
- SetShapeCommonColor(eraser, gxWhite);
- GXSetShapeViewPorts(eraser, 1, &dp->docViewPort);
- GXDrawShape(eraser);
-
- GXDisposeShape(eraser);
-
- dp->bottomClear = rect.right;
- }
- } else {
-
- rect.top = pp->start + GetParagraphHeight(dp, pp) + dp->viewRect.top - dp->top;
- rect.bottom = dp->bottomClear;
- rect.left = dp->viewRect.left;
- rect.right = dp->viewRect.right;
-
- if(rect.top < rect.bottom) {
-
- aRect.top = ff(rect.top);
- aRect.left = ff(rect.left);
- aRect.bottom = ff(rect.bottom);
- aRect.right = ff(rect.right);
-
- eraser = GXNewRectangle(&aRect);
-
- /* This ignores is needed because we do not keep track of the current
- clip of the view port. Thus, we will often set the clip to the same rect
- which generates a notice*/
-
- #ifdef debugging
- GXIgnoreGraphicsNotice(clip_already_set);
- #endif
-
- GXSetViewPortClip(dp->docViewPort, eraser);
-
- #ifdef debugging
- GXPopGraphicsNotice();
- #endif
-
- SetShapeCommonColor(eraser, gxWhite);
- GXSetShapeViewPorts(eraser, 1, &dp->docViewPort);
- GXDrawShape(eraser);
-
- GXDisposeShape(eraser);
-
- dp->bottomClear = rect.top;
- }
- }
-
- }
-
- static void GetOffset(DocPtr dp, short offsetType, long * newOffset, Boolean * endOfLine)
- {
- long docOffset;
- short paraIndex, paraOffset;
- short lineIndex, lineOffset;
- ParaPtr pp;
- LinePtr lp;
-
- docOffset = *newOffset;
-
- GetParagraphIndexAndOffset(dp, docOffset, ¶Index, ¶Offset, *endOfLine);
-
- pp = *dp->paragraphs + paraIndex;
- docOffset = pp->docOffset;
-
- switch(offsetType) {
-
- case kUpOffset:
-
- *endOfLine = (dp->maxLineOffset != 0);
-
- GetLineIndexAndOffset(dp, pp, paraOffset, &lineIndex, &lineOffset, *endOfLine);
-
- if(paraIndex == 0&& lineIndex == 0)
- return;
-
- if(lineIndex == 0) {
- pp--;
- lineIndex = pp->numLines - 1;
- } else
- lineIndex--;
-
- goto skip;
-
- case kDownOffset:
-
- *endOfLine = (dp->maxLineOffset != 0);
-
- GetLineIndexAndOffset(dp, pp, paraOffset, &lineIndex, &lineOffset, *endOfLine);
-
- if(paraIndex == (dp->numParagraphs - 1) && lineIndex == (pp->numLines - 1))
- return;
-
- if(lineIndex == (pp->numLines - 1)) {
- pp++;
- lineIndex = 0;
- } else
- lineIndex++;
-
- skip:
-
- lp = *pp->lines + lineIndex;
- lineOffset = dp->maxLineOffset;
-
- if(lineOffset > lp->numText) {
-
- lineOffset = lp->numText;
-
- if(lineIndex == (pp->numLines - 1))
- lineOffset--; /* end of paragraph is allways a single byte '\n' */
-
- }
-
- *newOffset = pp->docOffset + lp->paraOffset + lineOffset;
-
- return;
-
- case kVisualRightOffset:
-
- if(paraOffset != pp->numText - 1)
- break;
-
- if(paraIndex < (dp->numParagraphs - 1))
- docOffset++; /* end of paragraph is allways a single byte '\n' */
-
- *newOffset = docOffset + paraOffset;
- *endOfLine = false;
- return;
-
- case kPreviousOffset:
- case kVisualLeftOffset:
-
- if(paraOffset > 0)
- break;
-
- if(paraIndex > 0)
- docOffset--; /* end of paragraph is allways a single byte '\n' */
-
- *newOffset = docOffset;
- *endOfLine = false;
- return;
-
- }
-
- *newOffset = docOffset + GetParagraphOffset(dp, pp, offsetType, paraOffset);
- *endOfLine = false;
- }
-
-